package com.wgtgt.swing_paint;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 * Hello world!
 *
 */
public class Main {
	public static void main(String[] args) {
		System.out.println("Hello World!");
		String path = "F:\\abc.png";
		JFrame frame = new MyFrame();
		JPanel jp = new JPanel();
		frame.add(jp);
		frame.setSize(900, 500);
		frame.setVisible(true);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		FileOutputStream output = null;
		try {
			output = new FileOutputStream(new File(path));
		} catch (FileNotFoundException e1) {
			e1.printStackTrace();
		}
		BufferedImage createImage = new BufferedImage(800, 450, BufferedImage.TYPE_INT_RGB);
		Graphics graphics = createImage.getGraphics();
		frame.paint(graphics);
		try {
			ImageIO.write(createImage, "png", output);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
